#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
typedef long long ll;
int n,nn;
ll x,sum = 0;
set<ll> s;
vector<ll> t;
pair<ll,ll> nums[N];
int main(){
  freopen("kte.in","r",stdin);
  freopen("kte.out","w",stdout);
  ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
  cin >> n;
  nn = n;
  int cnt = 0;
  while(n--){
    ++cnt;
    cin >> x;
    if(cnt <= 3000 || nn <= 30000){
      if(s.find(x) != s.end()){
        t.erase(lower_bound(t.begin(),t.end(),x));
        s.erase(s.find(x));
      }else{
        t.insert(lower_bound(t.begin(),t.end(),x),x);
        s.insert(x);
      }
      if(t.size() <= 1){
        cout << 0 << "\n";
        continue;
      }
      ll sum = 0;
      for(int i = 0; i < t.size() - 1; ++ i){
        sum += t[i];
        nums[i+1].second = sum;
      }
      sum = 0;
      for(int i = t.size() - 1; i ; -- i){
        sum += t[i];
        nums[t.size()-i].first = sum;
      }
      int k = t.size() - 1;
      sort(nums+1,nums+k+1);
      nums[0].first = -1e18;
      ll tot = 0;
      for(int i = 1; i <= k; ++ i){
        if(nums[i].second <= nums[i-1].first)tot += nums[i].first - nums[i-1].first;
        else tot += nums[i].first - nums[i].second;
      }
      cout << tot << "\n";
    }else{
      if(s.find(x) != s.end())s.erase(s.find(x)),sum -= x;
      else s.insert(x),sum += x;
      if(s.size() <= 1){cout << 0 << "\n";}
      else cout << sum - 2*(*s.begin()) << "\n";
    }
  }
  return 0;
}